package net.yegong.matrix;

/**
 * @author cooper
 */
public class SymmetricMatrix extends SquareMatrix {
	public SymmetricMatrix(float[] matrix, int size, MatrixType type) {
		super(matrix, size, type);
		for (int i = 0; i < size; ++i) {
			for (int j = 0; j < size; ++j) {
				if (array[i + j * size] != array[i * size + j])
					throw new SymmetricException();
			}
		}
	}

	public SymmetricMatrix(SymmetricMatrix m) {
		super(MatrixHelper.copy(m.array), m.nRow, FORTRAN);
	}

	public SymmetricMatrix(int order) {
		super(order);
	}

	@Override
	public SymmetricMatrix clone() {
		Matrix m = super.clone();
		return new SymmetricMatrix(m.array, m.nCol, FORTRAN);
	}

	@Override
	public SymmetricMatrix transpose() {
		return clone();
	}

	@Override
	public void set(int i, int j, float value) {
		super.set(i, j, value);
		super.set(j, i, value);
	}

	@Override
	public void setRow(int index, RowVector row) {
		super.setRow(index, row);
		super.setColumn(index, row.transpose());
	}

	@Override
	public void setColumn(int index, ColumnVector col) {
		super.setRow(index, col.transpose());
		super.setColumn(index, col);
	}
}
